package com.buildings.util;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;

import com.bigkoo.pickerview.OptionsPickerView;
import com.bigkoo.pickerview.TimePickerView;
import com.buildings.bean.AddressBean;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class PickViewUtil {

  public static void showPickerViewOne(Context context, String title, List<String> options1Items,
      final OptionsPickerView.OnOptionsSelectListener listener) {// 弹出选择器（省市区三级联动）
    if (TextUtils.isEmpty(title)) {
      title = "请选择";
    }
    OptionsPickerView pvOptions =
        new OptionsPickerView.Builder(context, new OptionsPickerView.OnOptionsSelectListener() {
          @Override public void onOptionsSelect(int options1, int options2, int options3, View v) {
            //返回的分别是三个级别的选中位置
            //                etAddress.setText(options1Items.get(options1).getPickerViewText() + "  "
            //                        + options2Items.get(options1).get(options2) );
            listener.onOptionsSelect(options1, options2, options3, v);
          }
        }).setTitleText(title)
            .setDividerColor(Color.BLACK)
            .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
            .setContentTextSize(20)
            .build();
    pvOptions.setPicker(options1Items);//一级选择器
    //        pvOptions.setPicker(options1Items, options2Items);//二级选择器
    //        pvOptions.setPicker(options1Items, options2Items, options3Items);//三级选择器
    pvOptions.show();
  }

  public static void showTimePickerView(Context context, String title, boolean isYear,

      TimePickerView.OnTimeSelectListener listener) {
    TimePickerView pvTime =
        new TimePickerView.Builder(context, listener).setTitleText(title)
            .setDividerColor(Color.BLACK)
            .setRange(1979,Calendar.getInstance().get(Calendar.YEAR))
            .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
            .setTitleSize(20)//标题文字大小
            .setSubCalSize(18)//确定和取消文字大小
            .setType(isYear ? new boolean[] { true, false, false, false, false, false }
                : new boolean[] { false, true, false, false, false, false })
            .setContentSize(18)
            .isCenterLabel(true)
            .setLabel("", "", "", "", "", "")
            .build();
    pvTime.show();
  }
}
